
import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jydoctorflutter/config/user_data.dart';
import 'package:jydoctorflutter/pages/login/LoginVC.dart';
import 'package:jydoctorflutter/pages/login/LoginView.dart';
import 'package:jydoctorflutter/utils/tools/log_util.dart';
import 'package:logger/logger.dart';
import 'package:page_transition/page_transition.dart';

import '../main_tabbar/view.dart';

class SplashScreenPage extends StatefulWidget {
  const SplashScreenPage({super.key});

  State<SplashScreenPage> createState() => _SplashScreenPageState();
}

class _SplashScreenPageState extends State<SplashScreenPage> with SingleTickerProviderStateMixin{
  @override
  void initState() {
    super.initState();
    // // 注入逻辑
       Get.lazyPut(() => LoginVC());
    // Get.lazyPut(() => InvoicesMainLogic());
    // Get.lazyPut(() => EstimatesMainLogic());
    // Get.lazyPut(() => ClientsMainLogic());
    // Get.lazyPut(() => ToolsMainLogic());
    // Get.lazyPut(() => StatisticsMainLogic());
    // Get.lazyPut(() => LoginLogic());
    // // logo 渐变动画
    // _logoFadeController = AnimationController(duration: const Duration(milliseconds: 1200), vsync: this);
    // _logoFadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(_logoFadeController);
    // _logoFadeController.forward();
  }

  @override
  void dispose() {
    // _logoFadeController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return  FutureBuilder<Widget>(
        future: _islogin(),
        builder: (context,snapshot){
      return Container(
               color:Colors.white,
               child:  Column(
                 children: [
                   Container(
                     child: Container(
                       child: Image.asset('assets/icon/icon.png'),
                       margin: EdgeInsets.only(top: 141,bottom:0 ),
                       width: 76,height: 76,
                     ),
                   ),
                   Container(
                     height: 28,
                     margin: EdgeInsets.only(top: 12,bottom:36),
                     child:RichText(text:TextSpan(text: '精准防艾',style: TextStyle(color: Colors.black,fontSize: 20,fontWeight:FontWeight.w600)))
                   ),
                   //
                   if (snapshot.connectionState == ConnectionState.done && snapshot.hasData)
                        FutureBuilder(future: Future.delayed(const Duration(milliseconds: 5000)),
                                builder:(context,innerSnapshot){
                            if (innerSnapshot.connectionState == ConnectionState.done ) {
                                 print("12333333333");
                                WidgetsBinding.instance.addPostFrameCallback((_){
                                  Navigator.of(context,).pushReplacement(PageTransition(child: snapshot.data!,type: PageTransitionType.bottomToTop));
                               });
                             }
                             return Container();
                            }
                        )
                 ]
          ),
      );
    });
  }
}
Future <Widget> _islogin() async {
  final token =  await UserData.instance.getToken();
  String  isHava = token ?? '';

     print("1233444");
  return isHava.isEmpty ? LoginView() : MainTabbarPage();
}